/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.JD.DiselLog;

import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author admin
 */
public class UpdateDiselQuantityOfMachine {

    public UpdateDiselQuantityOfMachine(String machineName,String quantity) {


          SessionFactory sessionFactory = com.JD.master.Hibernate.Master_HibernateUtil.getSessionFactory();
        Session session = sessionFactory.openSession();
        Transaction transaction = session.beginTransaction();


        Criteria cr = session.createCriteria(com.JD.master.Hibernate.MachineMaster.class);
        cr.add(Restrictions.eq("machineName", machineName));
        List results = cr.list();

        for (Object object : results) {
            com.JD.master.Hibernate.MachineMaster machineMaster = (com.JD.master.Hibernate.MachineMaster) object;




               machineMaster.setRawField4(Integer.parseInt(quantity)+Integer.parseInt(machineMaster.getRawField4())+"");
                session.save(machineMaster);
                transaction.commit();


        }


    }




}
